package com.ibm.testbed.script.wizards;

import org.eclipse.jdt.core.JavaCore;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import com.ibm.testbed.script.adjust.TestbedElementChangeListener;
import com.ibm.testbed.script.adjust.TestbedPartListener;

public class ScriptPlugin extends AbstractUIPlugin {

	public ScriptPlugin() {
		// TODO Auto-generated constructor stub
	}

	public void start(BundleContext context) throws Exception {

		super.start(context);

		JavaCore.addElementChangedListener(new TestbedElementChangeListener());
		Display.getDefault().timerExec(1000, new Runnable() {

			public void run() {

				IWorkbenchWindow window = PlatformUI.getWorkbench()
						.getActiveWorkbenchWindow();
				if (window != null) {
					if (window.getActivePage() != null) {
						window.getActivePage().addPartListener(
								new TestbedPartListener());

						return;
					}

				}
				Display.getDefault().timerExec(1000, this);

			}
		});
	}

}
